<?php
include_once LIB_PATH . DS . 'getFileObject.php';
use OSS\Core\OssException;
use OSS\OssClient;
function strage($bucket, $path)
{
    $objects = getFileObject($bucket);
    foreach ($objects as $object) {
        $localFile = trim($path . DS . $object);
        $localPath = dirname($localFile);
        if (!is_dir($localPath)) {
            mkdir($localPath, 0755, true);
        }
        ossDownload($bucket, $object, $localFile);
    }
}

function ossDownload($bucket, $object, $localfile)
{
    $objects = getFileObject($bucket);
    $options = array(
        OssClient::OSS_FILE_DOWNLOAD => $localfile,
    );
    try {
        $ossClient = new OssClient(ossAccessKeyId, ossAccessKeySecret, ossEndpoint);
        $ossClient->getObject($bucket, $object, $options);
    } catch (OssException $e) {
        printf(__FUNCTION__ . ": FAILED\n");
        printf($e->getMessage() . "\n");
        return;
    }
    print(__FUNCTION__ . ": OK, please check localfile:" . $localfile . "\n");
}
